		var searchParams;
		$(function(){
			//添加按钮事件
			$('#addpromotion').on('click', function() {
				
				var node=businessTable.datagrid('getSelected');
				if (node) {
					addpromotion(node.BUSINESS_ID);
				} else {
					layer.msg('请选择一条商家！', {
						time : 1000
					})
				}
			});
			//修改按钮事件
			$('#editpromotion').on('click', function() {
				var node = promotionTable.datagrid('getSelected');
				if (node) {
					openeditpromotion(node.PROMOTION_ID);
				} else {
					layer.msg('请选择一条数据！', {
						time : 1000
					})
				}
			});
			//删除按钮事件
			$('#delpromotion').on('click', function() {
				delpromotion();
			});
			//查询按钮事件
			$('#searchpromotion').on('click', function() {
				opensearchpromotion();
			});
		});
		//Table表格数据源
		var promotionTable = $('#promotion_table').datagrid(BasicData.createDatagrid({  
			url :'',
			frozenColumns:[[
				{field:'ck',checkbox:true},
				{title:'PROMOTION_ID',field:'PROMOTION_ID',hidden:true}
			]],
			columns:[[
				{field:'BUSINESS_ID',title:'商户id',width:'10%',hidden:true,align:'center'},
				{field:'TITLE',title:'标题',width:'10%',align:'center'},
				{field:'PROMOTION_TYPE',title:'优惠类型',width:'10%',align:'center',
					formatter : function(value, row, index) {
                       if(value=='0') return '满减'
                       if(value=='1') return '折扣'
                       if(value=='2') return '随机立减'
					
					}	
				},
				{field:'MONEY',title:'满足的金额',width:'10%',align:'center'},
				{field:'START_MONEY',title:'满减值/折扣额度/随机最小值',width:'10%',align:'center'},
				{field:'END_MONEY',title:'随机最大值',width:'10%',align:'center'},
				{field:'START_DATE',title:'起始日期',width:'10%',align:'center'},
				{field:'END_DATE',title:'结束日期',width:'10%',align:'center'},
				{field:'START_TIME',title:'起始时间',width:'10%',align:'center'},
				{field:'END_TIME',title:'结束时间',width:'10%',align:'center'},
				{field:'DISABLE',title:'是否禁用',width:'10%',align:'center'},
				{field:'STATUS',title:'状态',width:'10%',hidden:true,align:'center'},
				{field:'DESCRIBE',title:'描述',width:'10%',align:'center'},
				{field:'SCOPE',title:'使用范围',width:'10%',hidden:true,align:'center'},
				{field:'CREATEDATE',title:'创建时间',width:'10%',align:'center',},
				{field:'WEEK',title:'有效星期',width:'10%',align:'center'}
			]],
			onDblClickRow:function(rowIndex, rowData){
				
			}
		}));  
		//打开查询窗体
		function opensearchpromotion(){
			parent.layer.open({
				title : '查询条件',
				type : 2,
				btn : ['查询','重置'],
				yes : function(index,layero) {
					var iframeWin = parent.window[layero.find('iframe')[0]['name']];
					searchParams = iframeWin.$("#searchForm").serialize();
					var newparam = iframeWin.$("#searchForm").serializeJSON();
					iframeWin.parentIframeName = window.name;
					$.extend(newparam,promotionTable.queryParams);
					$('#promotion_table').datagrid('load',newparam);
					parent.layer.close(index);
				},
				btn2 : function(index, layero) {
					var iframeWin = parent.window[layero.find('iframe')[0]['name']];
					iframeWin.parentIframeName = window.name;
					iframeWin.$("#searchForm").form("clear");
					return false;
				},
				area : [ '70%', '70%' ],
				content : rootpath + '/promotion/toSearch.do?'+searchParams
			});
		}
		//编辑打开窗体
		function openeditpromotion(PROMOTION_ID){
			parent.layer.open({
				title : '信息',
				type : 2,
				btn : ['保存','关闭'],
				yes : function(index,layero) {
					var iframeWin = parent.window[layero.find('iframe')[0]['name']];
					iframeWin.parentIframeName = window.name;
					iframeWin.$("#dataForm").submit();
				},
				btn2 : function(index, layero) {
				},
				area : [ '90%', '90%' ],
				content : rootpath + '/promotion/toEdit.do?PROMOTION_ID='+PROMOTION_ID
			});
		}
		//编辑打开窗体
		function addpromotion(BUSINESS_ID){
			parent.layer.open({
				title : '信息',
				type : 2,
				btn : ['保存','关闭'],
				yes : function(index,layero) {
					var iframeWin = parent.window[layero.find('iframe')[0]['name']];
					iframeWin.parentIframeName = window.name;
					iframeWin.$("#dataForm").submit();
				},
				btn2 : function(index, layero) {
				},
				area : [ '90%', '90%' ],
				content : rootpath + '/promotion/toEdit.do?BUSINESS_ID='+BUSINESS_ID
			});
		}
		
		//删除
		function delpromotion() {
			var node = dataTable.datagrid('getSelected');
			if (node) {
				layer.confirm('您确定要删除吗？', {
					btn : [ '确定', '取消' ]
				}, function(index, layero) {
				    layer.close(index);
					$.uitools.showLoading();//打开处理中遮罩层
					$.ajax({
						cache : true,
						type : "POST",
						url : rootpath + '/promotion/delete.do',
						data : {
							PROMOTION_ID : node.PROMOTION_ID
						},
						error : function(request) {
							$.uitools.hideLoading();//关闭处理中遮罩层
							layer.msg('系统异常！', {
								icon : 2,
								time : 1000
							})
						},
						success : function(data) {
							$.uitools.hideLoading();//关闭处理中遮罩层
							if (data.success){
								layer.msg('删除成功！', {
									icon : 1,
									time : 1000
								}, function() {
									dataTable.datagrid('reload');
								})
							}else {
								layer.msg('删除异常！', {
									icon : 2,
									time : 1000
								})
							}
						}
					});
				}, function() {
				});
			} else {
				layer.msg('请选择一条数据！', {
					time : 1000
				})
			}
		}
